package org.ptkparty.client.view.players;

import org.ptkparty.client.model.UserProxy;

import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.core.client.GWT;
import com.google.gwt.safehtml.client.SafeHtmlTemplates;
import com.google.gwt.safehtml.client.SafeHtmlTemplates.Template;
import com.google.gwt.safehtml.shared.SafeHtml;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;

public class PlayerCell extends AbstractCell<UserProxy> {

	public interface Template extends SafeHtmlTemplates {

		@Template("<img height='16' width='16 'src='{0}'/> {1}")
		SafeHtml playerTemplate(String urlImage, String label);

		@Template("{0}")
		SafeHtml playerTemplate(String label);

		@Template("<img height='16' width='16 'src='{0}'/> {1} {2}")
		SafeHtml playerTemplateWithData(String urlImage, String label, String data);

		@Template("{0} <b>{1}</b>")
		SafeHtml playerTemplateWithData(String label, String data);

	}

	public final static Template template = GWT.create(Template.class);

	@Override
	public void render(com.google.gwt.cell.client.Cell.Context context, UserProxy value, SafeHtmlBuilder sb) {
		if (value.getImage() != null) {
			sb.append(template.playerTemplate(value.getImage(), value.getNickname()));
		} else {
			sb.append(template.playerTemplate(value.getNickname()));
		}
	}
}
